package com.example.demo.entity;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.io.Serializable;

//@Component
public class Address implements Serializable {
    private String province;
    private String city;
    private String district;
    private String street;

    public Address() {
    }

    public Address(String province, String city, String district, String street) {
        this.province = province;
        this.city = city;
        this.district = district;
        this.street = street;
    }

    public Address(String addr) {
        String[] parts = addr.split(",");
        if (parts.length >= 1) this.province = parts[0];
        if (parts.length >= 2) this.city = parts[1];
        if (parts.length >= 3) this.district = parts[2];
        if (parts.length >= 4) this.street = parts[3];
    }

    public void setValue(String addr) {
        String[] parts = addr.split(",");
        if (parts.length >= 1) this.province = parts[0];
        if (parts.length >= 2) this.city = parts[1];
        if (parts.length >= 3) this.district = parts[2];
        if (parts.length >= 4) this.street = parts[3];
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getDistrict() {
        return district;
    }

    public void setDistrict(String district) {
        this.district = district;
    }

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    @Override
    public String toString() {
        return province + "," + city + "," + district + "," + street;
    }
}
